from typing import Optional, List

from langchain_core.runnables import RunnableConfig
from langgraph.constants import Send
from .base import BaseNodes, tool_node
from ...models.graph import GraphState

class SystemNodes(BaseNodes):

    def __init__(self, parallel_nodes: Optional[List[str]] = None, **kwargs):
        super().__init__(**kwargs)
        self.parallel_nodes = parallel_nodes or []

    @tool_node()
    def interrupt(self, state: GraphState, *, config: Optional[RunnableConfig] = None):
        ext = state.ext or {}
        if ext.get("skip_interrupt", False):
            ext["skip_interrupt"] = False
            return self.node_success(ext=ext)
        return self.wait_human_feedback()

    @tool_node()
    def blank(self, state: GraphState, *, config: Optional[RunnableConfig] = None):
        return self.node_success()

    def parallel_execute(self, state: GraphState, *, config: Optional[RunnableConfig] = None):
        sends = []
        for node_name in self.parallel_nodes:
            sends.append(Send(node_name, state))
        return sends
